package com.zhuiyun.pm.client.bid.chat.mapper;


import com.zhuiyun.pm.client.action.entity.GoodsEntity;
import com.zhuiyun.pm.client.bid.chat.entity.BidRecord;
import com.zhuiyun.pm.client.bid.chat.entity.Email;
import com.zhuiyun.pm.config.BaseMapper;
import org.apache.ibatis.annotations.*;


import java.util.List;

/**
 * @ClassName BidRecordMapper
 * @Description 保存拍卖出价历史记录
 * @Author lyp
 * @Date 2023/3/15 10:06
 **/
@Mapper
public interface BidRecordMapper extends BaseMapper<BidRecord>{

    /**
     * @author lyp
     * @description 保存拍卖出价记录sql
     * @date 2023/3/16 13:50
     * @param
     * @param: list
     * @return int
     */
    @Insert("<script>insert into client_record_of_id(user_id,bid,max_bid,bid_time,max_bid_user_id,room_id,login_name) values " +
            "<foreach collection='list' item='item' separator=','>(#{item.userId},#{item.bid},#{item.maxBid},#{item.bidTime},#{item.maxBidUserId},#{item.roomId},#{item.loginName})</foreach></script>")
    int saveBidRecord(List<BidRecord> list);

    /**
     * @author lyp
     * @description 用于redis中最终价删除之后来数据库查询最终价
     * @date 2023/3/16 13:54
     * @param
     * @return BidRecord
     */
    @Select("<script>select * from client_record_of_id where room_id = #{key1} order by id DESC limit 1</script>")
    @Results({
            @Result(property = "userId",column = "user_id"),
            @Result(property = "maxBid",column = "max_bid"),
            @Result(property = "bidTime",column = "bid_time"),
            @Result(property = "maxBidUserId",column = "max_bid_user_id"),
    })
    BidRecord getMaxBid(String key1);

    /**
     * @author lyp
     * @description 用于redis中历史出价删除之后来数据库查询历史出价
     * @date 2023/3/16 14:34
     * @param
     * @return BidRecord
     */
    @Select("<script>select * from client_record_of_id where room_id = #{roomId}</script>")
    @Results({
            @Result(property = "userId",column = "user_id"),
            @Result(property = "maxBid",column = "max_bid"),
            @Result(property = "bidTime",column = "bid_time"),
            @Result(property = "maxBidUserId",column = "max_bid_user_id"),
            @Result(property = "roomId",column = "room_id"),
    })
    List<BidRecord> getRecordOfBid(String roomId);

    /**
     * @author lyp
     * @description 根据物品id查询物品信息
     * @date 2023/3/23 19:12
     * @param
     * @param: id
     * @return GoodsEntity
     */
    @Select("<script>select * from client_goods_info where id = #{id} limit 1</script>")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "goodsId",column = "goods_id"),
            @Result(property = "startPrice",column = "start_price"),
            @Result(property = "imgId",column = "img_id"),
            @Result(property = "earnestMoneyStatus",column = "earnest_money_status"),
            @Result(property = "endPrice",column = "end_price"),
            @Result(property = "transactionStatus",column = "transaction_status"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
    })
    GoodsEntity getItemById(Integer id);


}
